
	mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:false,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
	});
	
	
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var currenPage=1;
    var pageSize=10;
    var total_page=0;
    var total_count=0;
    
    window.onload = function(){
    	mui.ajax({
				url: apiurl + "Article/book_list/",
				data: {'p':currenPage,'size':pageSize,'user_id':uid,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						total_page=res.total_page;
						total_count=res.sum;
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll .mui-table-view').append(htm);
					}
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
			 mui.plusReady(function(){
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			    
			    mui(".mui-table-view").on('tap','.mui-table-view-cell .see_detail',function(){
			    	var aid=this.getAttribute("data-id");
			    	mui.openWindow({
					    id:'news_detail.html',
					    url:'news_detail.html',
					    extras:{
					       article_id:aid //自定义扩展参数，可以用来处理页面间传值
					    },
					    show: {
							autoShow:false
						},
						waiting: {
							autoShow: true,
							title:'正在加载...'
						}
				  	});
			    })
			    
			});

    }

    function get_data(data){
    	var htm='';
		for(i in data) {
			/*
			 * <li class="mui-table-view-cell">
							<a class="" onclick="see_detail(2)">
							<p>我的消息</p>
							<span class="mui-pull-right setting_right">2015-05-07 18:59:58</span>
							</a>
							</li>
			 */
			htm += '<li class="mui-table-view-cell">';
			htm+='<a class="see_detail" data-id="'+data[i]['id']+'">';
			htm+='<p>'+data[i]['title']+'</p><span class="mui-pull-right setting_right">'+data[i]['add_time']+'</span>';
			htm+='</a>';
			htm+='</li>';
		}
		return htm;
    }


	function pullupRefresh() {
		setTimeout(function() {
			currenPage++;
			mui.ajax({
				url: apiurl + "Article/book_list/",
				data: {'p':currenPage,'size':pageSize,'user_id':uid,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll .mui-table-view').append(htm);
					}
					
					if(currenPage < total_page){
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    /*能上拉*/
	                }else{
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);/*不能上拉*/
	                }
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
		}, 1500);
	}
	
